<template>
  <div class="layout-container">
    <el-aside>
      <el-menu
          class="el-menu-vertical"
          :default-active="activeMenu"
          background-color="#304156"
          text-color="#bfcbd9"
          active-text-color="#409EFF"
          router
      >
        <el-menu-item index="/home">
          <el-icon>
            <Monitor/>
          </el-icon>
          <span>系统首页</span>
        </el-menu-item>
        <el-menu-item index="/child">
          <el-icon>
            <User/>
          </el-icon>
          <span>子女管理</span>
        </el-menu-item>
        <el-menu-item index="/elder">
          <el-icon>
            <User/>
          </el-icon>
          <span>老人管理</span>
        </el-menu-item>
        <el-menu-item index="/doctor">
          <el-icon>
            <User/>
          </el-icon>
          <span>医生管理</span>
        </el-menu-item>
        <el-menu-item index="/community">
          <el-icon>
            <House/>
          </el-icon>
          <span>社区管理</span>
        </el-menu-item>
      </el-menu>
    </el-aside>
    <el-container>
      <el-header>
        <div class="header-content">
          <h2>益康社区养老管理系统</h2>
          <el-button type="danger" @click="handleLogout">退出登录</el-button>
        </div>
      </el-header>
      <el-main>
        <router-view v-slot="{ Component }">
          <transition name="fade-transform" mode="out-in">
            <keep-alive>
              <component :is="Component" :key="$route.path"/>
            </keep-alive>
          </transition>
        </router-view>
      </el-main>
    </el-container>
  </div>
</template>

<script setup lang="ts">
import {computed} from 'vue'
import {useRouter, useRoute} from 'vue-router'
import {useUserStore} from '@/stores/user'
import {ElMessage} from 'element-plus'
import {Monitor, User, UserFilled, House} from '@element-plus/icons-vue'

const router = useRouter()
const route = useRoute()
const userStore = useUserStore()

const activeMenu = computed(() => route.path)

const handleLogout = () => {
  userStore.logout()
  ElMessage.success('退出成功')
  router.push('/login')
}
</script>

<style scoped>
.layout-container {
  min-height: 100vh;
  display: flex;
  margin: 0;
  padding: 0;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  overflow: hidden;
}

.el-aside {
  background-color: #304156;
  width: 240px !important;
  height: 100%;
  flex-shrink: 0;
}

.el-menu-vertical {
  height: 100%;
  border-right: none;
}

.header-content {
  width: 100%;
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 10px;
}

.header-content h2 {
  margin: 0;
  color: #303133;
  font-size: 20px;
}

.el-main {
  background-color: #f0f2f5;
  padding: 20px;
  overflow-y: auto;
}
</style> 